/*
 * WinnerAlphamon.java
 *
 * Created on 21. november 2007, 15:15
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package hotgammon.domain;
import java.util.*;

/**
 *
 * @author nick
 */
public class WinnerDeltamon implements Winner {
    private Dice dice;
    private Board board;
    
    /** Creates a new instance of WinnerAlphamon */
    public WinnerDeltamon(Dice dice, Board board) {
        this.dice = dice;
        this.board = board;
    }
    
    public Color winner() {
        int redQuarter = 0;
        int blackQuarter = 0;
        
        ArrayList<Location> redQuarterArray = new ArrayList<Location>();
            redQuarterArray.add(Location.R1);
            redQuarterArray.add(Location.R2);
            redQuarterArray.add(Location.R3);
            redQuarterArray.add(Location.R4);
            redQuarterArray.add(Location.R5);
            redQuarterArray.add(Location.R6);
            
        ArrayList<Location> blackQuarterArray = new ArrayList<Location>();
            blackQuarterArray.add(Location.B1);
            blackQuarterArray.add(Location.B2);
            blackQuarterArray.add(Location.B3);
            blackQuarterArray.add(Location.B4);
            blackQuarterArray.add(Location.B5);
            blackQuarterArray.add(Location.B6);

        for (Location l : redQuarterArray) {
            if (board.getColor(l) == Color.RED) {
                redQuarter += board.getCount(l);
            }
        }

        for (Location l : blackQuarterArray) {
            if (board.getColor(l) == Color.BLACK) {
                blackQuarter += board.getCount(l);
            }
        }
        
        if (redQuarter == 15) {
            return Color.RED;
        }
        if (blackQuarter == 15) {
            return Color.BLACK;
        }   

        return Color.NONE;
    }
}
